package com.baidu.mapapi;

import android.graphics.Canvas;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.view.KeyEvent;
import android.view.MotionEvent;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Iterator;

public abstract class ItemizedOverlay<Item extends OverlayItem> extends Overlay
  implements Overlay.Snappable
{
  private static int d = -1;
  private boolean a = true;
  private Drawable b;
  private Drawable c;
  private ItemizedOverlay<Item>.a e = null;
  private OnFocusChangeListener f = null;
  private int g = -1;
  private int h = -1;

  public ItemizedOverlay(Drawable paramDrawable)
  {
    this.b = paramDrawable;
    if (this.b != null)
    {
      this.c = new n().a(this.b);
      if (d == 0)
        a(this.b, b.c);
    }
  }

  private static Drawable a(Drawable paramDrawable, b paramb)
  {
    if ((paramDrawable == null) || (b.a == paramb))
      return null;
    Rect localRect1 = paramDrawable.getBounds();
    if ((localRect1.height() == 0) || (localRect1.width() == 0))
      paramDrawable.setBounds(0, 0, paramDrawable.getIntrinsicWidth(), paramDrawable.getIntrinsicHeight());
    Rect localRect2 = paramDrawable.getBounds();
    int i = localRect2.width() / 2;
    int j = -localRect2.height();
    b localb = b.b;
    int k = 0;
    if (paramb == localb)
    {
      j /= 2;
      k = -j;
    }
    paramDrawable.setBounds(-i, j, i, k);
    return paramDrawable;
  }

  static Drawable a(ItemizedOverlay<?> paramItemizedOverlay)
  {
    return paramItemizedOverlay.b;
  }

  private void a(Canvas paramCanvas, MapView paramMapView, boolean paramBoolean, OverlayItem paramOverlayItem, int paramInt)
  {
    Drawable localDrawable = paramOverlayItem.getMarker(paramInt);
    if ((localDrawable == null) && (this.b == null))
      return;
    boolean bool;
    if (localDrawable != null)
      if (this.b == null)
      {
        bool = false;
        if (bool)
        {
          if (!paramBoolean)
            break label136;
          localDrawable = this.c;
          this.c.setBounds(this.b.copyBounds());
          n.a(this.c, this.b);
        }
      }
    Point localPoint;
    while (true)
    {
      localPoint = paramMapView.getProjection().toPixels(paramOverlayItem.getPoint(), null);
      if (!bool)
        break label145;
      Overlay.a(paramCanvas, localDrawable, localPoint.x, localPoint.y);
      return;
      bool = localDrawable.equals(this.b);
      break;
      bool = true;
      break;
      label136: localDrawable = this.b;
    }
    label145: Overlay.drawAt(paramCanvas, localDrawable, localPoint.x, localPoint.y, paramBoolean);
  }

  protected static Drawable boundCenter(Drawable paramDrawable)
  {
    d = 2;
    return a(paramDrawable, b.b);
  }

  protected static Drawable boundCenterBottom(Drawable paramDrawable)
  {
    d = 1;
    return a(paramDrawable, b.c);
  }

  protected abstract Item createItem(int paramInt);

  public void draw(Canvas paramCanvas, MapView paramMapView, boolean paramBoolean)
  {
    if (this.e != null)
    {
      int i = this.e.a();
      for (int j = 0; j < i; j++)
      {
        int k = getIndexToDraw(j);
        if (k != this.h)
        {
          OverlayItem localOverlayItem2 = getItem(k);
          Point localPoint = paramMapView.getProjection().toPixels(localOverlayItem2.getPoint(), null);
          int m = paramMapView.getLeft();
          int n = paramMapView.getRight();
          int i1 = paramMapView.getTop();
          int i2 = paramMapView.getBottom();
          localPoint.x = (m + localPoint.x);
          localPoint.y = (i1 + localPoint.y);
          if ((localPoint.x >= m) && (localPoint.y >= i1) && (localPoint.x <= n) && (localPoint.y <= i2))
            a(paramCanvas, paramMapView, paramBoolean, localOverlayItem2, 0);
        }
      }
    }
    if (this.a)
    {
      OverlayItem localOverlayItem1 = getFocus();
      if (localOverlayItem1 != null)
        a(paramCanvas, paramMapView, false, localOverlayItem1, 4);
    }
  }

  public GeoPoint getCenter()
  {
    return getItem(getIndexToDraw(0)).getPoint();
  }

  public Item getFocus()
  {
    int i = this.h;
    OverlayItem localOverlayItem = null;
    if (i != -1)
      localOverlayItem = this.e.a(this.h);
    return localOverlayItem;
  }

  protected int getIndexToDraw(int paramInt)
  {
    return this.e.b(paramInt);
  }

  public final Item getItem(int paramInt)
  {
    return this.e.a(paramInt);
  }

  public final int getLastFocusedIndex()
  {
    return this.g;
  }

  public int getLatSpanE6()
  {
    return this.e.a(true);
  }

  public int getLonSpanE6()
  {
    return this.e.a(false);
  }

  protected boolean hitTest(OverlayItem paramOverlayItem, Drawable paramDrawable, int paramInt1, int paramInt2)
  {
    Rect localRect = paramDrawable.getBounds();
    localRect.left -= 10;
    localRect.right = (10 + localRect.right);
    localRect.bottom = (10 + localRect.bottom);
    localRect.top -= 10;
    boolean bool = localRect.contains(paramInt1, paramInt2);
    localRect.left = (10 + localRect.left);
    localRect.right -= 10;
    localRect.bottom -= 10;
    localRect.top = (10 + localRect.top);
    return bool;
  }

  public Item nextFocus(boolean paramBoolean)
  {
    if (this.e.a() == 0);
    int i;
    label86: 
    do
    {
      do
      {
        return null;
        if (this.g != -1)
          break;
      }
      while (this.h == -1);
      return this.e.a(0);
      if (this.h != -1);
      for (i = this.h; ; i = this.g)
      {
        if (!paramBoolean)
          break label86;
        if (i == -1 + this.e.a())
          break;
        return this.e.a(i + 1);
      }
    }
    while (i == 0);
    return this.e.a(i - 1);
  }

  public boolean onKeyUp(int paramInt, KeyEvent paramKeyEvent, MapView paramMapView)
  {
    return false;
  }

  public boolean onSnapToItem(int paramInt1, int paramInt2, Point paramPoint, MapView paramMapView)
  {
    int i = this.e.a();
    boolean bool1 = false;
    if (i > 0)
    {
      Point localPoint = new Point();
      OverlayItem localOverlayItem = this.e.a(0);
      paramMapView.getProjection().toPixels(localOverlayItem.getPoint(), localPoint);
      boolean bool2 = hitTest(localOverlayItem, localOverlayItem.mMarker, paramInt1 - localPoint.x, paramInt2 - localPoint.y);
      bool1 = false;
      if (bool2)
      {
        paramPoint.x = localPoint.x;
        paramPoint.y = localPoint.y;
        bool1 = true;
      }
    }
    return bool1;
  }

  protected boolean onTap(int paramInt)
  {
    if (paramInt != this.h)
      setFocus(getItem(paramInt));
    return false;
  }

  public boolean onTap(GeoPoint paramGeoPoint, MapView paramMapView)
  {
    if (this.e != null)
      return this.e.a(paramGeoPoint, paramMapView);
    return false;
  }

  public boolean onTouchEvent(MotionEvent paramMotionEvent, MapView paramMapView)
  {
    return false;
  }

  public boolean onTrackballEvent(MotionEvent paramMotionEvent, MapView paramMapView)
  {
    return false;
  }

  protected final void populate()
  {
    this.e = new a();
    this.g = -1;
    this.h = -1;
  }

  public void setDrawFocusedItem(boolean paramBoolean)
  {
    this.a = paramBoolean;
  }

  public void setFocus(Item paramItem)
  {
    if ((paramItem != null) && (this.h == this.e.a(paramItem)));
    do
    {
      do
      {
        return;
        if ((paramItem == null) && (this.h != -1))
        {
          if (this.f != null)
            this.f.onFocusChanged(this, paramItem);
          this.h = -1;
          return;
        }
        this.h = this.e.a(paramItem);
      }
      while (this.h == -1);
      setLastFocusedIndex(this.h);
    }
    while (this.f == null);
    this.f.onFocusChanged(this, paramItem);
  }

  protected void setLastFocusedIndex(int paramInt)
  {
    this.g = paramInt;
  }

  public void setOnFocusChangeListener(OnFocusChangeListener paramOnFocusChangeListener)
  {
    this.f = paramOnFocusChangeListener;
  }

  public abstract int size();

  public static abstract interface OnFocusChangeListener
  {
    public abstract void onFocusChanged(ItemizedOverlay<?> paramItemizedOverlay, OverlayItem paramOverlayItem);
  }

  class a
    implements Comparator<Integer>
  {
    private ArrayList<Item> b;
    private ArrayList<Integer> c;
    private ItemizedOverlay<Item> d = ItemizedOverlay.this;

    public a()
    {
      int i = ItemizedOverlay.this.size();
      this.b = new ArrayList(i);
      this.c = new ArrayList(i);
      for (int j = 0; j < i; j++)
      {
        this.c.add(Integer.valueOf(j));
        OverlayItem localOverlayItem = ItemizedOverlay.this.createItem(j);
        this.b.add(localOverlayItem);
      }
      Collections.sort(this.c, this);
    }

    private Point a(OverlayItem paramOverlayItem, Projection paramProjection, Point paramPoint)
    {
      Point localPoint = paramProjection.toPixels(paramOverlayItem.getPoint(), null);
      return new Point(paramPoint.x - localPoint.x, paramPoint.y - localPoint.y);
    }

    public final int a()
    {
      return this.b.size();
    }

    public final int a(Item paramItem)
    {
      if (paramItem != null)
        for (int i = 0; ; i++)
        {
          if (i >= this.b.size())
            i = -1;
          while (paramItem.equals(this.b.get(i)))
            return i;
        }
      return -1;
    }

    public int a(Integer paramInteger1, Integer paramInteger2)
    {
      int i = 1;
      GeoPoint localGeoPoint1 = ((OverlayItem)this.b.get(paramInteger1.intValue())).getPoint();
      GeoPoint localGeoPoint2 = ((OverlayItem)this.b.get(paramInteger2.intValue())).getPoint();
      if (localGeoPoint1.getLatitudeE6() > localGeoPoint2.getLatitudeE6())
        i = -1;
      while (localGeoPoint1.getLatitudeE6() < localGeoPoint2.getLatitudeE6())
        return i;
      if (localGeoPoint1.getLongitudeE6() < localGeoPoint2.getLongitudeE6())
        return -1;
      if (localGeoPoint1.getLongitudeE6() == localGeoPoint2.getLongitudeE6());
      for (int j = 0; ; j = i)
        return j;
    }

    public final int a(boolean paramBoolean)
    {
      if (this.b.size() == 0)
        return 0;
      Iterator localIterator = this.b.iterator();
      int i = -2147483648;
      int j = 2147483647;
      if (!localIterator.hasNext())
        return i - j;
      GeoPoint localGeoPoint = ((OverlayItem)localIterator.next()).getPoint();
      int k;
      if (paramBoolean)
      {
        k = localGeoPoint.getLatitudeE6();
        label66: if (k > i)
          i = k;
        if (k >= j)
          break label99;
      }
      while (true)
      {
        j = k;
        break;
        k = localGeoPoint.getLongitudeE6();
        break label66;
        label99: k = j;
      }
    }

    public final Item a(int paramInt)
    {
      return (OverlayItem)this.b.get(paramInt);
    }

    public final boolean a(GeoPoint paramGeoPoint, MapView paramMapView)
    {
      Projection localProjection = paramMapView.getProjection();
      Point localPoint1 = localProjection.toPixels(paramGeoPoint, null);
      int i = this.b.size();
      int j = 0;
      double d1;
      if (j < i)
      {
        OverlayItem localOverlayItem = (OverlayItem)this.b.get(j);
        Point localPoint2 = a(localOverlayItem, localProjection, localPoint1);
        Drawable localDrawable = localOverlayItem.mMarker;
        if (localDrawable == null)
          localDrawable = ItemizedOverlay.a(this.d);
        if (this.d.hitTest(localOverlayItem, localDrawable, localPoint2.x, localPoint2.y))
        {
          d1 = localPoint2.x * localPoint2.x + localPoint2.y * localPoint2.y;
          label130: if ((d1 < 0.0D) || (d1 >= 1.7976931348623157E+308D));
        }
      }
      for (int k = j; ; k = -1)
      {
        if (-1 != k)
        {
          return this.d.onTap(k);
          j++;
          break;
        }
        this.d.setFocus(null);
        return false;
        d1 = -1.0D;
        break label130;
      }
    }

    public final int b(int paramInt)
    {
      return ((Integer)this.c.get(paramInt)).intValue();
    }
  }

  static enum b
  {
    static
    {
      b[] arrayOfb = new b[3];
      arrayOfb[0] = a;
      arrayOfb[1] = b;
      arrayOfb[2] = c;
    }

    private b(String paramString, int paramInt)
    {
    }
  }
}

/* Location:           C:\Documents and Settings\Administrator\classes_dex2jar.jar
 * Qualified Name:     com.baidu.mapapi.ItemizedOverlay
 * JD-Core Version:    0.6.2
 */